package com.ystarkotlin.utils

import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.core.content.ContextCompat
import com.blankj.utilcode.util.ConvertUtils
import com.blankj.utilcode.util.ToastUtils
import com.ystarkotlin.R
/**
 * Created by Ystar
 * Data 2019/9/4
 * 自己写一哈。保证统一修改 ,或者自定义
 */
 class MyToastUtils {
    companion object {
        fun showShort(context: Context, str: String) {
            ToastUtils.setBgColor(ContextCompat.getColor(context, R.color.transparent_half_black))
            ToastUtils.setMsgColor(ContextCompat.getColor(context, R.color.white))
            ToastUtils.setGravity(Gravity.BOTTOM, 0, ConvertUtils.dp2px(100f))
            ToastUtils.showShort(str)
        }

        /*自定义viewToast*/
        fun ShowCustomSUC(context: Context, str: String) {
            val toast = Toast(context)
            val view = LayoutInflater.from(context).inflate(R.layout.item_toast, null)
            var  textView :TextView =view.findViewById(R.id.tv_sus)
            textView.setText(str)
            toast.setGravity(Gravity.CENTER, 0, 0)
            toast.duration = Toast.LENGTH_SHORT
            toast.view = view
            toast.view.alpha = 0.8f
            toast.view.background=ContextCompat.getDrawable(context,R.drawable.item_toast)
            toast.show()

        }

        fun ShowCustomLongSUC(context: Context, str: String) {
            val toast = Toast(context)
            val view = LayoutInflater.from(context).inflate(R.layout.item_toast, null)
            var  textView :TextView =view.findViewById(R.id.tv_sus)
            textView.setText(str)
            toast.setGravity(Gravity.CENTER, 0, 0)
            toast.duration = Toast.LENGTH_LONG
            toast.view = view
            toast.view.alpha = 0.8f
            toast.view.background=ContextCompat.getDrawable(context,R.drawable.item_toast)
            toast.show()

        }

        fun ShowCustomError(context: Context, str: String) {
            val toast = Toast(context)
            val view = LayoutInflater.from(context).inflate(R.layout.item_toast, null)
            val imageView:ImageView = view.findViewById(R.id.toast_img)
            ImgUtils.load(context, R.mipmap.icon_submit_error, imageView)
            var  textView :TextView =view.findViewById(R.id.tv_sus)
            textView.setText(str)
            toast.setGravity(Gravity.CENTER, 0, 0)
            toast.duration = Toast.LENGTH_LONG
            toast.view = view
            toast.view.alpha = 0.8f
            toast.view.background=ContextCompat.getDrawable(context,R.drawable.item_toast)
            toast.show()

        }

    }
}
